package conc.testme.tela;

import android.content.Context;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import conc.testme.Assertiva;


public class CheckBoxLinkado extends CheckBox {
	public Assertiva assertiva;
	private Respondidas2Scroll resp2Scroll;
	public CheckBoxLinkado(Assertiva assertiva, Context context, Respondidas2Scroll resp2Scroll
			){
		super(context);
		this.resp2Scroll = resp2Scroll;
		this.assertiva = assertiva;
		addOnChangeListener();
		
	}
	
	public void addOnChangeListener(){
		this.setOnCheckedChangeListener(new OnCheckedChangeListener()
		{
		    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
		    {
		        if ( isChecked )
		        {		        	
		            assertiva.setRespostaAssinalada(true);
		            resp2Scroll.aumentaNumeroDeResposta();
		        }
		        else{
		        	assertiva.setRespostaAssinalada(false);
		        	resp2Scroll.diminuiNumeroDeResposta();
		        }
		        
		        if(resp2Scroll.getNumeroDeResposta() > 0){
		        	resp2Scroll.marcarComoRespondida();
		        	
		        }
		        else{
		        	resp2Scroll.marcarComoNaoRespondida();
		        }

		    }
		});
		
	}
}
